package com.molichuxing.services.infrastructure.convertor;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.molichuxing.framework.utils.StringUtil;
import com.molichuxing.services.business.dto.request.create.MotRequestCreateDto;
import com.molichuxing.services.infrastructure.bean.*;
import com.molichuxing.services.infrastructure.dto.request.create.ThirdMotCreateDto;
import com.molichuxing.services.util.JsonUtils;
import org.springframework.beans.BeanUtils;

import com.molichuxing.services.infrastructure.dto.response.GztDrivingLicenseNotifyLogDto;
import com.molichuxing.services.infrastructure.dto.response.GztIdverifyNotifyLogDto;
import com.molichuxing.services.infrastructure.dto.response.GztThreeverifyNotifyLogDto;
import com.molichuxing.services.infrastructure.dto.response.PyDrivingLicenseNotifyLogDto;
import com.molichuxing.services.infrastructure.dto.response.PyIdverifyNotifyLogDto;
import com.molichuxing.services.infrastructure.dto.response.PyThreeverifyNotifyLogDto;
import com.molichuxing.services.sdk.sms.PropertiesUtil;

/**
 * 
 * @author liyg
 * 数据转换类
 * 
 */
public class Convert {

	public static List<GztIdverifyNotifyLogDto> toGztIdverifyNotifyLogDto(List<GztIdverifyNotifyLogBean> beanList){
		List<GztIdverifyNotifyLogDto> dtoList = null;;
		if (beanList != null && beanList.size() > 0) {
			dtoList = new ArrayList<>();
			for (GztIdverifyNotifyLogBean bean : beanList) {
				dtoList.add(toGztIdverifyNotifyLogDto(bean));
			}
		}
		
		return dtoList;
	}
	
	public static GztIdverifyNotifyLogDto toGztIdverifyNotifyLogDto(GztIdverifyNotifyLogBean bean) {
		GztIdverifyNotifyLogDto beanDto = null;
		if (bean != null) {
			beanDto = new GztIdverifyNotifyLogDto();
			BeanUtils.copyProperties(bean, beanDto);
			beanDto.setResultMessage(bean.getMessage());
			beanDto.setRequestTime(bean.getGmtCreate());
			beanDto.setIdNumber(bean.getUserId());
			beanDto.setRealName(bean.getUserName());
		}
		return beanDto;
	}

	public static List<PyIdverifyNotifyLogDto> toPyIdverifyNotifyLogDto(List<PyIdverifyNotifyLogBean> beanList) {
		List<PyIdverifyNotifyLogDto> dtoList = null;;
		if (beanList != null && beanList.size() > 0) {
			dtoList = new ArrayList<>();
			for (PyIdverifyNotifyLogBean bean : beanList) {
				dtoList.add(toPyIdverifyNotifyLogDto(bean));
			}
		}
		
		return dtoList;
	}
	
	public static PyIdverifyNotifyLogDto toPyIdverifyNotifyLogDto(PyIdverifyNotifyLogBean bean) {
		PyIdverifyNotifyLogDto beanDto = null;
		if (bean != null) {
			beanDto = new PyIdverifyNotifyLogDto();
			BeanUtils.copyProperties(bean, beanDto);
			beanDto.setRequestTime(bean.getGmtCreate());
			beanDto.setIdNumber(bean.getUserId());
			beanDto.setRealName(bean.getUserName());
			if(bean.getTreatResult() != null && bean.getTreatResult() ==3) {
				beanDto.setTreatResultStr(bean.getErrorMessage());	
			}
		}
		return beanDto;
	}

	public static List<GztThreeverifyNotifyLogDto> GztThreeverifyNotifyLogDto(List<GztThreeverifyNotifyLogBean> beanList) {
		List<GztThreeverifyNotifyLogDto> dtoList = null;;
		if (beanList != null && beanList.size() > 0) {
			dtoList = new ArrayList<>();
			for (GztThreeverifyNotifyLogBean bean : beanList) {
				dtoList.add(GztThreeverifyNotifyLogDto(bean));
			}
		}
		
		return dtoList;
	}
	
	public static GztThreeverifyNotifyLogDto GztThreeverifyNotifyLogDto(GztThreeverifyNotifyLogBean bean) {
		GztThreeverifyNotifyLogDto beanDto = null;
		if (bean != null) {
			beanDto = new GztThreeverifyNotifyLogDto();
			BeanUtils.copyProperties(bean, beanDto);
			beanDto.setRequestTime(bean.getGmtCreate());
			beanDto.setIdNumber(bean.getIdNumber());
			beanDto.setRealName(bean.getFullName());
			beanDto.setUserPhone(bean.getPhoneNumber());
		}
		return beanDto;
	}

	public static List<PyThreeverifyNotifyLogDto> PyThreeverifyNotifyLogDto(List<PyThreeverifyNotifyLogBean> beanList) {
		List<PyThreeverifyNotifyLogDto> dtoList = null;;
		if (beanList != null && beanList.size() > 0) {
			dtoList = new ArrayList<>();
			for (PyThreeverifyNotifyLogBean bean : beanList) {
				dtoList.add(PyThreeverifyNotifyLogDto(bean));
			}
		}
		
		return dtoList;
	}
	
	
	public static PyThreeverifyNotifyLogDto PyThreeverifyNotifyLogDto(PyThreeverifyNotifyLogBean bean) {
		PyThreeverifyNotifyLogDto beanDto = null;
		if (bean != null) {
			beanDto = new PyThreeverifyNotifyLogDto();
			BeanUtils.copyProperties(bean, beanDto);
			beanDto.setRequestTime(bean.getGmtCreate());
			beanDto.setIdNumber(bean.getIdNumber());
			beanDto.setRealName(bean.getFullName());
			beanDto.setUserPhone(bean.getPhoneNumber());
			if(bean.getTreatResult() != null && bean.getTreatResult() ==3) {
				beanDto.setTreatResultStr(bean.getErrorMessage());	
			}
		}
		return beanDto;
	}

	public static List<GztDrivingLicenseNotifyLogDto> toGztDrivingLicenseNotifyLogDto(
			List<GztDrivingLicenseNotifyLogBean> beanList) {
		List<GztDrivingLicenseNotifyLogDto> dtoList = null;;
		if (beanList != null && beanList.size() > 0) {
			dtoList = new ArrayList<>();
			for (GztDrivingLicenseNotifyLogBean bean : beanList) {
				dtoList.add(toGztDrivingLicenseNotifyLogDto(bean));
			}
		}
		
		return dtoList;
	}
	
	public static GztDrivingLicenseNotifyLogDto toGztDrivingLicenseNotifyLogDto(GztDrivingLicenseNotifyLogBean bean) {
		GztDrivingLicenseNotifyLogDto beanDto = null;
		if (bean != null) {
			beanDto = new GztDrivingLicenseNotifyLogDto();
			BeanUtils.copyProperties(bean, beanDto);
			beanDto.setRequestTime(bean.getGmtCreate());
			beanDto.setRealName(bean.getFullName());
			String ztValue = bean.getZt();
			if(null != ztValue) {
				Pattern p = Pattern.compile("^[A-Za-z]+$");
				Matcher m = p.matcher(ztValue);
				if(m.matches()) {
					String messageValue ="";
		             for(int i=0;i<bean.getZt().length();i++){
		                 messageValue=messageValue+ztValue.charAt(i)+""+PropertiesUtil.getMessage(ztValue.charAt(i)+"")+";";
		             }
		             beanDto.setStatus(messageValue.substring(0,messageValue.length()-1));
				}
			}
			beanDto.setCarClass(bean.getZjcx());
			
		}
		return beanDto;
	}

	public static List<PyDrivingLicenseNotifyLogDto> toPyDrivingLicenseNotifyLogDto(
			List<PyDrivingLicenseNotifyLogBean> beanList) {
		List<PyDrivingLicenseNotifyLogDto> dtoList = null;;
		if (beanList != null && beanList.size() > 0) {
			dtoList = new ArrayList<>();
			for (PyDrivingLicenseNotifyLogBean bean : beanList) {
				dtoList.add(toPyDrivingLicenseNotifyLogDto(bean));
			}
		}
		
		return dtoList;
	}
	
	public static PyDrivingLicenseNotifyLogDto toPyDrivingLicenseNotifyLogDto(PyDrivingLicenseNotifyLogBean bean) {
		PyDrivingLicenseNotifyLogDto beanDto = null;
		if (bean != null) {
			beanDto = new PyDrivingLicenseNotifyLogDto();
			BeanUtils.copyProperties(bean, beanDto);
			beanDto.setRequestTime(bean.getGmtCreate());
			beanDto.setIdNumber(bean.getUserId());
			beanDto.setRealName(bean.getUserName());
			if(bean.getTreatResult() != null && bean.getTreatResult() ==3) {
				beanDto.setTreatResultStr(bean.getErrorMessage());	
			}
		}
		return beanDto;
	}

	public static MotLogBean toMotLogBean(ThirdMotCreateDto beanDto){
		MotLogBean bean = null;
		if(beanDto!=null){
			bean = new MotLogBean();
			BeanUtils.copyProperties(beanDto,bean);
		}
		return bean;
	}

	public static ThirdMotCreateDto toThirdMotCreateDto (MotRequestCreateDto beanDto,String resp){
		ThirdMotCreateDto bean = null;
		if(beanDto!=null){
			bean = new ThirdMotCreateDto();
			BeanUtils.copyProperties(beanDto,bean);
			if(!StringUtil.isEmpty(resp)){
				MotRequestCreateDto cdto = JsonUtils.parse(resp, MotRequestCreateDto.class);
				bean.setResultReason(cdto.getReason());
				bean.setResultCode(cdto.getResult());
			}
		}
		return bean;
	}
}
